package butines.game;

import java.awt.Color;
import java.awt.Graphics2D;

public class UnitStatusDecorator {

	private Color healthBarColorHealth = new Color(0, .85f, 0, .4f);
	private Color healthBarColorDamage = new Color(.85f, 0, 0, .4f);
	private int   healthBarWidth = 32;
	
	private int   cooldownBarWidth = 32;
	private Color cooldownBar = new Color(.85f, .85f, 0, .5f);
	
	public void drawHealthBar(Graphics2D g, float offsetX, float offsetY, Unit unit) {
		if (!unit.isDead()) {
			float x = unit.getPosition().x - offsetX - healthBarWidth / 2;
			float y = unit.getPosition().y - offsetY + 6;
			
			int drawX = Math.round(x);
			int drawY = Math.round(y);
			
			int wide = Math.round(healthBarWidth * ((float)unit.getHealth()/(float)unit.getMaxHealth()));
			
			g.setColor(healthBarColorHealth);
			g.fillRect(drawX, drawY, wide, 2);
			
			if (wide < healthBarWidth) {
				g.setColor(healthBarColorDamage);
				g.fillRect(drawX + wide, drawY, healthBarWidth - wide, 2);
			}
		}
	}
	
	
	
	public void drawCooldownBar(Graphics2D g, float offsetX, float offsetY, Unit unit) {
		if (unit.getCooldown().isLocked()) {
			float x = unit.getPosition().x - offsetX - healthBarWidth / 2;
			float y = unit.getPosition().y - offsetY + 4;
			
			int drawX = Math.round(x);
			int drawY = Math.round(y);
			
			int wide = Math.round(healthBarWidth * (unit.getCooldown().getCountdown()/unit.getCooldown().getWaitTime()));
			
			g.setColor(cooldownBar);
			g.fillRect(drawX, drawY, wide, 2);
		}
	}
	
}
